home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Bill's Win32Asm Page / binary1.txt < prev    next >
Text File  |  2000-05-25  |  5KB  |  117 lines

  1. Binary Numbers and Logic
  2. By Bill T.
  3. April 21, 1998
  4.  
  5.  
  6. Introduction
  7. -----------------------------------------------------------------------------
  8.  
  9. Having a basic understanding of how a computer works is essential to
  10. successfull programming.  Merely jumping in blindly and trying
  11. to hack some code together is not even a remotely good practice.
  12. Lacking the basic knowledge leads to bugged and bloated programs, not to
  13. mention long hours of coding, testing and debugging.  Wouldn't it be
  14. nice if everyone took the time to properly write a fast and efficient
  15. program, instead of rushing it out the door??
  16.  
  17. This lesson teaches the very basics of computers, binary numbers and
  18. boolean logic.  These are simple concepts, and if you do not already
  19. understand them, you would be well advised to do so...
  20.  
  21. Note:
  22.   This tutorial may actually lessen your knowledge of these topics...
  23.   This is not my intent, but could be the result nevertheless...
  24.   For a much more in-depth (and better) discussion, go to:
  25.   Binary Numbers:
  26.    http://webster.ucr.edu/Page_asm/ArtofAssembly/CH01/CH01-1.html#HEADING1-34
  27.   Boolean Logic:
  28.    http://webster.ucr.edu/Page_asm/ArtofAssembly/CH02/CH02-1.html#HEADING1-3
  29.  
  30.  
  31. Binary Numbers
  32. -----------------------------------------------------------------------------
  33.  
  34. Decimal Numbers:
  35.   In order to understand binary numbers, we must first refresh our knowledge
  36.   of the decimal number system.  If you do not already know this information,
  37.   assembly programming is probably not for you....instead, go and play some
  38.   video games, they're very entertaining.  Anyways...
  39.  
  40.   The decimal number system is base-10, meaning its digits are based upon
  41.   powers of 10.  It also means that each digit can represent one of 10
  42.   different values (0-9). For example, the number 443556 can represented as:
  43.  
  44.   443556 = 4x10^5 + 4x10^4 + 3x10^3 + 5x10^2 + 5x10^1 + 6x10^0
  45.          = 400,000 + 40,000 + 3,000 + 500 + 50 + 6
  46.  
  47. Binary Numbers:
  48.   The binary number system is base-2; its digits are based upon powers
  49.   of 2.  Each digit can represent one of 2 different values (0,1).
  50.   
  51.   To convert binary to decimal is simple:
  52.   0100 1010b = 0x2^7 + 1x2^6 + 0x2^5 + 0x2^4 + 1x2^3 + 0x2^2 + 1x2^1 + 0x2^0
  53.              = 64 + 8 + 2 = 74d
  54.  
  55.   Converting decimal to binary is slightly more complex:
  56.   You'll need to work backwards, finding the greatest power of 2 which is
  57.   less than the number you wish to convert.  Then continue for each lesser
  58.   power of 2 until 2^0.
  59.  
  60.   For Example, convert 1998 to binary:
  61.  
  62.     1x2^10 = 1024      1998-1024 = 974
  63.     1x2^9  = 512       974-512 = 462
  64.     1x2^8  = 256       462-256 = 206
  65.     1x2^7  = 128       206-128 = 78
  66.     1x2^6  = 64        78-64 = 14
  67.     ...
  68.     1x2^3  = 8         14-8 = 6
  69.     1x2^2  = 4         6-4 = 2
  70.     1x2^1  = 2         2-2 = 0
  71.  
  72.     1998d = 0111 1100 1110b
  73.  
  74.   In a computer, all data is stored in binary form.  Each binary digit in a
  75.   computers is known as a bit. A byte is equal to 8 bits, while a word is
  76.   16 bits, and a dword is 32 bits.
  77.   
  78. Hexadecimal Numbers:
  79.   Hexadecimal (Hex) numbers are base-16. They are a concise way of
  80.   representing binary numbers.  It represents each byte of data as a base-16
  81.   number.  Because there are only 10 numerals, the letters A-F are used for
  82.   the remaining 6 digits. Following is a table of binary numbers and their
  83.   hexadecimal equivalents:
  84.  
  85.   Bin   Hex    Bin   Hex    Bin   Hex    Bin   Hex
  86.   0000  0      0100  4      1000  8      1100  C
  87.   0001  1      0101  5      1001  9      1101  D
  88.   0010  2      0110  6      1010  A      1110  E
  89.   0011  3      0111  7      1011  B      1111  F
  90.  
  91.   Therefore: 0010 1001 1010b = 29Ah
  92.  
  93.   As you can see, 29A is much easier to read and write than it is in binary
  94.   form.  Plus, the conversion is trivial, so it makes sense to use hex
  95.   numbers when dealing with computers...
  96.                                    
  97.  
  98. Boolean Logic
  99. -----------------------------------------------------------------------------
  100.  
  101. Everyone should remeber logic from math class.. If not heres a brief
  102. introduction to it.  Boolean logic is a math system closed over the values
  103. 0 and 1. I will not give a complete discussion of boolean logic, just
  104. a few minor points that may be useful for programming.
  105.  
  106.   AND            OR             XOR            NOT
  107.   X  Y   Z       X  Y   Z       X  Y   Z       X  Z
  108.   0  0   0       0  0   0       0  0   0       0  1
  109.   0  1   0       0  1   1       0  1   1       1  0
  110.   1  0   0       1  0   1       1  0   1
  111.   1  1   1       1  1   1       1  1   0
  112.  
  113.  
  114. -----------------------------------------------------------------------------
  115.  
  116. Copyright (C) 1998
  117. Bill T.  (billasm@usa.net)